﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using DTO;
using System.ComponentModel;

namespace BUS
{
    public class CustomerBUS
    {
        CustomerDAO customerDao = new CustomerDAO();

        public int InsertCustomer(CustomerDTO cusDto)
        {
            if (customerDao.CheckExistsCode(cusDto.CustomerCode))
            {
                return 0;
            }

            return customerDao.InsertCustomer(cusDto);
        }

        public List<CustomerDTO> GetCustomerList()
        {
            return customerDao.GetCustomerList();
        }

        public bool CheckExistsCode(string code)
        {
            return customerDao.CheckExistsCode(code);
        }

        public bool UpdateCustomer(CustomerDTO cusDTO)
        {
            return customerDao.UpdateCustomer(cusDTO);
        }

        public bool UpdateCustomerDebtMoney(int cusID, double debtMoney)
        {
            return customerDao.UpdateCustomerDebtMoney(cusID, debtMoney);
        }

        public CustomerDTO GetCustomerByID(int ID)
        {
            return customerDao.GetCustomerByID(ID);
        }

        public BindingList<CustomerDTO> GetNewBindingListCustomer()
        {
            return customerDao.GetNewBindingListCustomer();
        }

        public bool DeleteCustomer(int ID)
        {
            return customerDao.DeleteCustomer(ID);
        }

        public CustomerDTO GetCustomerByCode(string code)
        {
            return customerDao.GetCustomerByCode(code);
        }

        public bool CheckCustomerDebt(CustomerDTO customer)
        {
            ParameterBUS paraBUS = new ParameterBUS();
            float MaxDebt = paraBUS.GetParameterValueByCode(ParameterCode.MaxDebt.ToString());

            if (customer.CustomerDebtMoney > MaxDebt)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public bool UpdateCustomerDebtFromInvoice(int id, float total)
        {
            return customerDao.UpdateCustomerDebtFromInvoice(id, total);
        }

        public List<CustomerReportDTO> GetListCustomerForReport(int month)
        {
            return customerDao.GetListCustomerForReport(month);
        }
        public List<CustomerReportDTO> GetListCustomerForReport(int customerID, int month)
        {
            return customerDao.GetListCustomerForReport(customerID, month);
        }
    }
}
